#include "ChessShuffle.h"
#include <random>

ChessInit::ChessInit()
{
	for (short type = ChessType::BING; type <= ChessType::TIAO; ++type)
	{
		for (int cnt = 1; cnt <= 9; ++cnt)
		{
			for (int id = 1; id <= 4; ++id)
			{
				Chess chess;
				chess.id = id;
				chess.type = static_cast<ChessType>(type);
				chess.count = cnt;
				ChessShuffle::s_serialChessArry.push_back(chess);
			}
		}
	}

	for (short type = ChessType::DF; type <= ChessType::Bai; ++type)
	{
		for (int id = 1; id <= 4; ++id)
		{
			Chess chess;
			chess.id = id;
			chess.type = static_cast<ChessType>(type);
			chess.count = 0;
			ChessShuffle::s_serialChessArry.push_back(chess);
		}
	}
}

ChessInit::~ChessInit()
{
	if (!ChessShuffle::s_serialChessArry.empty())
	{
		ChessShuffle::s_serialChessArry.clear();
	}
}


std::vector<Chess> ChessShuffle::s_serialChessArry;
ChessInit ChessShuffle::s_chessGc;

const std::vector<Chess> ChessShuffle::getShuffleChessArry(short maxReperoty)
{
	std::random_device rd;
	short cbRandCount = 0;
	short cbPosition = 0;
	std::vector<Chess> initCardArryTmp(ChessShuffle::s_serialChessArry);
	std::vector<Chess> shuffleArry(maxReperoty);
	do
	{
		cbPosition = static_cast<short>(rd() % (maxReperoty - cbRandCount));
		shuffleArry[cbRandCount] = initCardArryTmp[cbPosition];
		cbRandCount++;
		initCardArryTmp[cbPosition] = initCardArryTmp[maxReperoty - cbRandCount];
	} while (cbRandCount < maxReperoty);

	return shuffleArry;
}
